package com.java.star.mall.front.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.java.star.mall.common.response.JsonPage;
import com.java.star.mall.common.response.JsonResult;
import com.java.star.mall.front.pojo.param.AckOrderParam;
import com.java.star.mall.front.pojo.param.OrderParam;
import com.java.star.mall.front.pojo.param.OrderQueryParam;
import com.java.star.mall.front.pojo.vo.AckOrderInfoVO;
import com.java.star.mall.front.pojo.vo.OrderListVO;
import com.java.star.mall.front.pojo.vo.SubmitOrderVO;
import com.java.star.mall.front.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 订单Controller
 */
@Api(value = "order", tags = "订单")
@RestController
@RequestMapping("/order")
@Validated
public class OrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation(value = "生成订单确认页信息")
    @ApiOperationSupport(order = 100)
    @PostMapping("/getAckOrderInfo")
    public JsonResult<AckOrderInfoVO> getAckOrderInfo(@Valid @RequestBody AckOrderParam ackOrderParam) {
        AckOrderInfoVO ackOrderInfo = orderService.getAckOrderInfo(ackOrderParam);
        return JsonResult.ok(ackOrderInfo);
    }

    @ApiOperation(value = "提交订单")
    @ApiOperationSupport(order = 200)
    @PostMapping("/submitOrder")
    public JsonResult<SubmitOrderVO> submitOrder(@Valid @RequestBody OrderParam orderParam) {
        SubmitOrderVO submitOrderVO = orderService.submitOrder(orderParam);
        return JsonResult.ok(submitOrderVO);
    }

    @ApiOperation(value = "查询订单列表")
    @ApiOperationSupport(order = 300)
    @GetMapping("/listOrder")
    public JsonResult<JsonPage<OrderListVO>> listOrder(OrderQueryParam orderQueryParam) {
        JsonPage<OrderListVO> jsonPage = orderService.listOrder(orderQueryParam);
        return JsonResult.ok(jsonPage);
    }

}
